package cit.project.capeclear;


import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

public class HistoryActivity extends Activity {

	private String[] HEADERS;
	private String[] TEXTS;

	@Override
	public void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// Create the view switcher
		HorizontalPager realViewSwitcher = new HorizontalPager(getApplicationContext());

		// Add some views to it
		HEADERS = getResources().getStringArray(R.array.historyTitles);
		TEXTS = getResources().getStringArray(R.array.HistoryTexts);


		for(int i=0; i<HEADERS.length; i++){
			RelativeLayout activityLayout = (RelativeLayout) getLayoutInflater().inflate(R.layout.history, null);

			final RelativeLayout tipLayout = (RelativeLayout) activityLayout.getChildAt(1);
			Button buttonOK = (Button)tipLayout.getChildAt(2);

			if(i==0)
				tipLayout.setVisibility(View.VISIBLE);

			buttonOK.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {

					tipLayout.startAnimation(AnimationUtils.loadAnimation(HistoryActivity.this, android.R.anim.fade_out));
					tipLayout.setVisibility(View.GONE);
					Log.v("cit.project.capeclear", "OK pressed");
				}
			});

			LinearLayout history = ((LinearLayout) activityLayout.getChildAt(0));


			LinearLayout linear1 =((LinearLayout)history.getChildAt(1)); 
			TextView header =((TextView)linear1.getChildAt(0));
			ScrollView scroll = ((ScrollView)history.getChildAt(3)); 
			LinearLayout linear2 =((LinearLayout)scroll.getChildAt(0)); 
			TextView txt=((TextView)linear2.getChildAt(0));
			txt.setText(Html.fromHtml(TEXTS[i]));
			header.setText(HEADERS[i]);

			LinearLayout linearPages =((LinearLayout)history.getChildAt(4));
			TextView pNumber =((TextView)linearPages.getChildAt(i));
			pNumber.setTextColor(0xFFFFFFFF);

			realViewSwitcher.addView(activityLayout);

		}





		// set as content view
		setContentView(realViewSwitcher);

		// Yeah, it really is as simple as this :-)

		/*
		 * Note that you can also define your own views directly in a resource XML, too by using:
		 * <com.github.ysamlan.horizontalpager.RealViewSwitcher
		 *     android:layout_width="fill_parent"
		 *     android:layout_height="fill_parent"
		 *     android:id="@+id/real_view_switcher">
		 *     <!-- your views here -->
		 * </com.github.ysamlan.horizontalpager.RealViewSwitcher>
		 */

		// OPTIONAL: listen for screen changes
		realViewSwitcher.setOnScreenSwitchListener(onScreenSwitchListener);
	}

	private final HorizontalPager.OnScreenSwitchListener onScreenSwitchListener =
			new HorizontalPager.OnScreenSwitchListener() {
		@Override
		public void onScreenSwitched(final int screen) {
			/*
			 * this method is executed if a screen has been activated, i.e. the screen is
			 * completely visible and the animation has stopped (might be useful for
			 * removing / adding new views)
			 */
			Log.d("HorizontalPager", "switched to screen: " + screen);
		}
	};
}


